home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / shadez.swf / scripts / Local / Game / Thing / CPath.as < prev    next >
Encoding:
Text File  |  2011-08-19  |  9.2 KB  |  321 lines

  1. package Local.Game.Thing
  2. {
  3.    import STC9.Math.CLineIntersection;
  4.    import flash.display.*;
  5.    import flash.events.*;
  6.    import flash.geom.*;
  7.    import flash.utils.getTimer;
  8.    
  9.    public class CPath
  10.    {
  11.        
  12.       
  13.       private var mPathIndex:Number;
  14.       
  15.       private var mPath:Array;
  16.       
  17.       private var pPath:Array;
  18.       
  19.       private var mPathLength:Number;
  20.       
  21.       public function CPath()
  22.       {
  23.          super();
  24.          mPathLength = 0;
  25.          mPathIndex = 0;
  26.          mPath = new Array();
  27.          pPath = new Array();
  28.       }
  29.       
  30.       public function get mPoint() : Point
  31.       {
  32.          var _loc1_:Object = null;
  33.          var _loc2_:Number = NaN;
  34.          _loc1_ = mPath[Math.floor(mPathIndex)];
  35.          _loc2_ = mPathIndex % 1;
  36.          return new Point(_loc1_.p1.x + _loc1_.d.x * _loc2_,_loc1_.p1.y + _loc1_.d.y * _loc2_);
  37.       }
  38.       
  39.       public function get mRadians() : Number
  40.       {
  41.          var _loc1_:int = 0;
  42.          var _loc2_:Number = NaN;
  43.          var _loc3_:Object = null;
  44.          var _loc4_:Object = null;
  45.          if(true)
  46.          {
  47.             _loc1_ = Math.floor(mPathIndex);
  48.             _loc2_ = mPathIndex % 1;
  49.          }
  50.          _loc3_ = mPath[_loc1_];
  51.          ┬º┬ºpush((_loc4_ = mPath[_loc1_ == mPath.length - 1 ? _loc1_ : _loc1_ + 1]).rads - _loc3_.rads);
  52.          if(true)
  53.          {
  54.             ┬º┬ºpush(┬º┬ºpop() * _loc2_);
  55.          }
  56.          return ┬º┬ºpop() + _loc3_.rads;
  57.       }
  58.       
  59.       public function SetPath_PD2(param1:Point, param2:Point, param3:Point, param4:Point = null) : void
  60.       {
  61.          var _loc5_:Point = null;
  62.          param4 = param4 == null ? new Point(-param2.x,param2.y) : param4;
  63.          if((_loc5_ = CLineIntersection.InfinatePD(param1,param2,param3,param4)) == null)
  64.          {
  65.             return;
  66.          }
  67.          SetPath([param1,_loc5_,param3]);
  68.       }
  69.       
  70.       public function OrientateThing(param1:CThingMain) : void
  71.       {
  72.          var _loc2_:int = 0;
  73.          var _loc3_:Number = NaN;
  74.          var _loc4_:Object = null;
  75.          var _loc5_:Object = null;
  76.          _loc2_ = Math.floor(mPathIndex);
  77.          _loc3_ = mPathIndex % 1;
  78.          _loc4_ = mPath[_loc2_];
  79.          _loc5_ = mPath[_loc2_ == mPath.length - 1 ? _loc2_ : _loc2_ + 1];
  80.          if(true)
  81.          {
  82.             param1.mPosition.x = _loc4_.p1.x + _loc4_.d.x * _loc3_;
  83.             if(true)
  84.             {
  85.                param1.mPosition.y = _loc4_.p1.y + _loc4_.d.y * _loc3_;
  86.                if(true)
  87.                {
  88.                   param1.mAngle.mAngleRAD = (_loc5_.rads - _loc4_.rads) * _loc3_ + _loc4_.rads;
  89.                }
  90.                if(param1.mOrientation == -1)
  91.                {
  92.                }
  93.                ┬º┬ºgoto(addr114);
  94.             }
  95.             param1.mAngle.InvertOrientation();
  96.          }
  97.          addr114:
  98.       }
  99.       
  100.       public function DrawPath(param1:Graphics) : void
  101.       {
  102.          var _loc2_:int = 0;
  103.          _loc2_ = 0;
  104.          while(_loc2_ < mPath.length)
  105.          {
  106.             param1.moveTo(mPath[_loc2_].p1.x,mPath[_loc2_].p1.y);
  107.             if(false)
  108.             {
  109.                break;
  110.             }
  111.             param1.lineTo(mPath[_loc2_].p2.x,mPath[_loc2_].p2.y);
  112.             if(true)
  113.             {
  114.                _loc2_ += 2;
  115.             }
  116.          }
  117.       }
  118.       
  119.       public function get mDelta() : Point
  120.       {
  121.          return Point.polar(1,mRadians);
  122.       }
  123.       
  124.       public function MoveAlong(param1:Number) : Boolean
  125.       {
  126.          var _loc2_:Number = NaN;
  127.          var _loc3_:Number = NaN;
  128.          loop0:
  129.          while(true)
  130.          {
  131.             ┬º┬ºpush(param1);
  132.             ┬º┬ºpush(0);
  133.             while(true)
  134.             {
  135.                if(┬º┬ºpop() <= ┬º┬ºpop())
  136.                {
  137.                   ┬º┬ºpush(true);
  138.                   break;
  139.                }
  140.                _loc2_ = Number(mPath[Math.floor(mPathIndex)].len);
  141.                ┬º┬ºpush(_loc2_);
  142.                ┬º┬ºpush(1);
  143.                if(false)
  144.                {
  145.                   continue;
  146.                }
  147.                ┬º┬ºpush(mPathIndex);
  148.                if(true)
  149.                {
  150.                   ┬º┬ºpush(┬º┬ºpop() % 1);
  151.                }
  152.                ┬º┬ºpush(┬º┬ºpop() - ┬º┬ºpop());
  153.                if(true)
  154.                {
  155.                   _loc3_ = ┬º┬ºpop() * ┬º┬ºpop();
  156.                   if(param1 > _loc2_)
  157.                   {
  158.                      mPathIndex = Math.floor(mPathIndex) + 1;
  159.                      addr57:
  160.                      param1 -= _loc2_;
  161.                   }
  162.                   else
  163.                   {
  164.                      ┬º┬ºpush(┬º┬ºfindproperty(mPathIndex));
  165.                      ┬º┬ºpush(mPathIndex);
  166.                      if(true)
  167.                      {
  168.                         ┬º┬ºpush(param1);
  169.                         if(true)
  170.                         {
  171.                            ┬º┬ºpush(┬º┬ºpop() / _loc2_);
  172.                         }
  173.                         ┬º┬ºpush(┬º┬ºpop() + ┬º┬ºpop());
  174.                      }
  175.                      ┬º┬ºpop().mPathIndex = ┬º┬ºpop();
  176.                      param1 = 0;
  177.                   }
  178.                   if(mPathIndex >= mPath.length)
  179.                   {
  180.                      ┬º┬ºpush(false);
  181.                      if(true)
  182.                      {
  183.                         return ┬º┬ºpop();
  184.                      }
  185.                      break;
  186.                   }
  187.                   continue loop0;
  188.                }
  189.                ┬º┬ºgoto(addr57);
  190.             }
  191.             return ┬º┬ºpop();
  192.          }
  193.       }
  194.       
  195.       public function SetPath(param1:Array) : void
  196.       {
  197.          var _loc2_:Number = NaN;
  198.          var _loc3_:int = 0;
  199.          var _loc4_:Object = null;
  200.          _loc2_ = getTimer();
  201.          _loc3_ = 0;
  202.          loop0:
  203.          while(true)
  204.          {
  205.             ┬º┬ºpush(_loc3_);
  206.             ┬º┬ºpush(param1.length - 1);
  207.             if(false)
  208.             {
  209.                break;
  210.             }
  211.             if(┬º┬ºpop() >= ┬º┬ºpop())
  212.             {
  213.                _loc3_ = 0;
  214.                while(true)
  215.                {
  216.                   ┬º┬ºpush(_loc3_);
  217.                   ┬º┬ºpush(pPath.length - 1);
  218.                   break loop0;
  219.                   addr62:
  220.                   _loc4_ = {
  221.                      "p1":pPath[_loc3_ + 0],
  222.                      "p2":pPath[_loc3_ + 1]
  223.                   };
  224.                   _loc4_.d = _loc4_.p2.subtract(_loc4_.p1);
  225.                   _loc4_.len = _loc4_.d.length;
  226.                   _loc4_.rads = GetRADS(_loc4_.d);
  227.                   mPathLength += _loc4_.len;
  228.                   if(_loc4_.len >= 1)
  229.                   {
  230.                      mPath.push(_loc4_);
  231.                   }
  232.                   _loc3_++;
  233.                }
  234.                ┬º┬ºgoto(addr123);
  235.             }
  236.             GeneratePath(param1[_loc3_],param1[_loc3_ + 1],param1[_loc3_ + 2],25);
  237.             _loc3_ += 2;
  238.          }
  239.          while(true)
  240.          {
  241.             if(┬º┬ºpop() < ┬º┬ºpop())
  242.             {
  243.                ┬º┬ºgoto(addr62);
  244.             }
  245.             addr123:
  246.             return;
  247.          }
  248.       }
  249.       
  250.       private function GetRADS(param1:Point) : Number
  251.       {
  252.          var _loc2_:* = NaN;
  253.          ┬º┬ºpush(Math.atan2(param1.y,param1.x));
  254.          if(true)
  255.          {
  256.             _loc2_ = ┬º┬ºpop();
  257.             ┬º┬ºpush(_loc2_);
  258.             if(true)
  259.             {
  260.                if(┬º┬ºpop() < 0)
  261.                {
  262.                   ┬º┬ºgoto(addr52);
  263.                }
  264.                else
  265.                {
  266.                   ┬º┬ºpush(_loc2_);
  267.                }
  268.                ┬º┬ºgoto(addr52);
  269.             }
  270.             ┬º┬ºpush(┬º┬ºpop());
  271.          }
  272.          addr52:
  273.          ┬º┬ºpush(_loc2_);
  274.          if(true)
  275.          {
  276.             ┬º┬ºpush(┬º┬ºpop() + Math.PI * 2);
  277.          }
  278.          return ┬º┬ºpop();
  279.       }
  280.       
  281.       public function GeneratePath(param1:Point, param2:Point, param3:Point, param4:Number) : void
  282.       {
  283.          var _loc5_:Point = null;
  284.          var _loc6_:Point = null;
  285.          var _loc7_:Number = NaN;
  286.          var _loc8_:Number = NaN;
  287.          var _loc9_:Number = NaN;
  288.          var _loc10_:Point = null;
  289.          var _loc11_:Point = null;
  290.          var _loc12_:int = 0;
  291.          _loc5_ = param2.subtract(param1);
  292.          _loc6_ = param3.subtract(param2);
  293.          if(true)
  294.          {
  295.             _loc7_ = _loc5_.length;
  296.             if(true)
  297.             {
  298.                _loc8_ = _loc6_.length;
  299.             }
  300.             _loc9_ = Math.ceil((_loc7_ > _loc8_ ? _loc7_ : _loc8_) / param4);
  301.          }
  302.          _loc10_ = param1.clone();
  303.          _loc11_ = param2.clone();
  304.          _loc5_.x /= _loc9_;
  305.          _loc5_.y /= _loc9_;
  306.          _loc6_.x /= _loc9_;
  307.          _loc6_.y /= _loc9_;
  308.          _loc12_ = 0;
  309.          while(_loc12_ <= _loc9_)
  310.          {
  311.             pPath.push(new Point((_loc11_.x - _loc10_.x) * _loc12_ / _loc9_ + _loc10_.x,(_loc11_.y - _loc10_.y) * _loc12_ / _loc9_ + _loc10_.y));
  312.             _loc12_++;
  313.             _loc10_.x += _loc5_.x;
  314.             _loc10_.y += _loc5_.y;
  315.             _loc11_.x += _loc6_.x;
  316.             _loc11_.y += _loc6_.y;
  317.          }
  318.       }
  319.    }
  320. }
  321.